package eclipse.util.maptools;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import eclipse.util.ERL;
/**
 * The Palate class is the form that holds all of the Objects required to edit the map.
 * This was generated in NetBeans so I will not write an in-depth description to how it works.
 */
/*
 * Copyright (c) 2009, TOD Productions All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *	- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *	- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *	-Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */
public final class Palette extends JInternalFrame 
{
	private static final long serialVersionUID = -8113292604932198390L;
	/** Creates new form Palette */
    public Palette() 
    {
    	tilesheetDisplay = new TilesheetDisplay();
        scrollTileSet = new javax.swing.JScrollPane(tilesheetDisplay);
        sliderTileSet = new javax.swing.JSlider();
        lblTileSet = new javax.swing.JLabel();
        
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("Tile Set Palette");

        sliderTileSet.setValue(0);        
        sliderTileSet.addChangeListener(new javax.swing.event.ChangeListener()
        {

			@Override
			public void stateChanged(ChangeEvent e) {
				sliderTileSetMouseDragged(e);				
			}
        	
        });

        lblTileSet.setText("Tile Set: 0 ");

        

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTileSet)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(sliderTileSet, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(scrollTileSet, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sliderTileSet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTileSet))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollTileSet, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
        tilesheetDisplay.setImage(new ERL(MapEditorApplication.workspace + "tiles/tiles0").openStream());        
        sliderTileSet.setMaximum(MapEditorApplication.TILESHEETS - 1);
        setClosable(true);
    }

    private final void sliderTileSetMouseDragged(javax.swing.event.ChangeEvent evt) 
    {                                               	
        lblTileSet.setText("Tile Set: " + sliderTileSet.getValue());
        tilesheetDisplay.setImage(
        	new ERL(MapEditorApplication.workspace + "tiles/tiles" + sliderTileSet.getValue()).openStream()
        );
        MapEditorApplication.selectSheet = sliderTileSet.getValue();
    }                                              
    // Variables declaration - do not modify
    private final JLabel lblTileSet;    
    private final JScrollPane scrollTileSet;
    private final JSlider sliderTileSet;
    public final TilesheetDisplay tilesheetDisplay;
    // End of variables declaration

}
